﻿Imports CrystalDecisions.Shared

Public Class frmEstadoDeDeuda
    Dim vectorBlock(16, 2) As String
    Dim VectorDepartamento(16, 5) As String
    Dim vectorFormasDePago(10, 2) As String
    Dim vectorDeuda(,) As String = {}
    Private Sub frmEstadoDeDeuda_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CargaDatosIniciales()

    End Sub
    Private Sub CargaDatosIniciales()
        listadoBlock()
    End Sub

    Private Sub listadoBlock()
        Dim i As Integer
        conectar()
        cmd.Connection = con
        cmd.CommandText = "SELECT ID,Nombre FROM tBlock"
        cmd.CommandType = CommandType.Text

        dr = cmd.ExecuteReader
        If dr.HasRows Then
            While dr.Read
                vectorBlock(i, 0) = dr("ID").ToString
                vectorBlock(i, 1) = dr("Nombre").ToString
                cbBlock.Items.Add(vectorBlock(i, 1))
                i += 1
            End While

        End If
        dr.Close()

        desconectar()

    End Sub
    Private Sub listadoDepartamento(ByVal IDBlock As Integer)
        Dim i As Integer
        Dim depa As String
        cbDepartamento.Items.Clear()
        conectar()

        cmd.Connection = con
        cmd.CommandText = "SELECT d.ID,d.IDBlock,d.NumeroActual,d.NumeroAnterior "
        cmd.CommandText += "FROM tDepartamento d "
        cmd.CommandText += "WHERE d.IDBlock=" + IDBlock.ToString
        cmd.CommandType = CommandType.Text

        dr = cmd.ExecuteReader
        If dr.HasRows Then
            While dr.Read()
                VectorDepartamento(i, 0) = dr("ID").ToString
                VectorDepartamento(i, 1) = dr("IDBlock").ToString
                VectorDepartamento(i, 2) = dr("NumeroActual").ToString
                VectorDepartamento(i, 3) = dr("NumeroAnterior").ToString
                depa = Trim(dr("NumeroActual").ToString) & " EX " & Trim(dr("NumeroAnterior").ToString)
                cbDepartamento.Items.Add(Trim(depa))
                i += 1
                depa = ""
            End While
        End If
        dr.Close()
        desconectar()
    End Sub

    Private Sub cbBlock_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbBlock.SelectedIndexChanged
        listadoDepartamento(CInt(cbBlock.Text))
    End Sub

    Private Sub btnGenerar_Click(sender As Object, e As EventArgs) Handles btnGenerar.Click
        Dim idDV As New ParameterDiscreteValue
        Dim idDepa As Integer
        Dim rptIngresoGastosComunes As New rptPagoGastosComunes
        idDV.Value = idDepa
        rptIngresoGastosComunes.DataSourceConnections(0).SetConnection("Driver={MySQL ODBC 5.2a Driver};Server=localhost;Port=3306;", "bdCoprevi", "root", "123456")
        'CTM QUE ME COSTÓ ENCONTRAR EL STRING DE CONEXION
        rptIngresoGastosComunes.SetParameterValue("pago", idDV)
        crv1.ReportSource = rptIngresoGastosComunes
    End Sub
End Class